package cn.ly.recursion.traingle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Traingle {
	
	static int inputNum;
	public static void main(String[] args) throws IOException {
		System.out.println("Enter a number:");
		inputNum = getInputNum();
		System.out.println(countTraingle(inputNum));
		
	}
	
	public static int getInputNum() throws IOException{
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(reader);
		return Integer.parseInt(br.readLine());
	}
	
	//n (n-1..1) 通过递归，用n 加上前面 n-1 到 1 的数字
	public static int countTraingle(int n){
		//1、退出条件当n=1时，返回 1
		if(n == 1){
			return 1;
		}else{//2、否则继续递归调用
			return n + countTraingle(n-1);
		}
	}
	
}
